package org.wwx.register.model;

import java.util.UUID;

/**
 * @date 2025/6/6
 * @author王闻薪
 */
public class ServiceInstance {
    private final String id;
    private final String host;
    private final int port;
    private final long registrationTime;
    private long lastRenewalTime;

    public ServiceInstance(String host, int port) {
        this.id = UUID.randomUUID().toString();
        this.host = host;
        this.port = port;
        this.registrationTime = System.currentTimeMillis();
        this.lastRenewalTime = this.registrationTime;
    }

    public String getId() {
        return id;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public long getRegistrationTime() {
        return registrationTime;
    }

    public long getLastRenewalTime() {
        return lastRenewalTime;
    }

    public void setLastRenewalTime(long lastRenewalTime) {
        this.lastRenewalTime = lastRenewalTime;
    }

    public void renewLease() {
        this.lastRenewalTime = System.currentTimeMillis();
    }
}
